package paul.idtech.lostTraveller.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Handler;
import android.view.SurfaceHolder;

public class UpdateThread extends Thread {

	protected SurfaceHolder surfaceHolder;
	protected Display display;
	protected Paint paint;
	protected Handler handler;
	protected Context context;
	boolean isSetup;
	public UpdateThread(SurfaceHolder holder, Context context, Display gameDisplay, Handler handler){
		
		
		surfaceHolder = holder;
		this.context = context;
		this.handler = handler;
		display = gameDisplay;
		this.paint = new Paint();
		isSetup = false;
		
	}
	
	@Override
	public void run(){
		
		while(true){
			
			Canvas canvas = surfaceHolder.lockCanvas();
			
			
			if(!isSetup){
				display.setup(this.context, canvas, paint);
				isSetup = true;
			}
			//update
			this.display.update(canvas, paint);
			this.display.draw(canvas, paint);
			surfaceHolder.unlockCanvasAndPost(canvas);
			
		}
		
	}
	
	
}
